package com.framework.web.demo.service;
import com.framework.web.demo.domain.Demo;
import com.framework.web.demo.repository.DemoRepository;
import com.framework.web.demo.repository.specifications.DemoSpecs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
* @Title: Service
* @Description: 业务层
* @author fusf
* @date 2016-08-28
* @version V1.0
*
*/
@Service
public class DemoService {

@Autowired
private DemoRepository  demoRepository;

/**
* 新增或者保存
* @param demo
* @return
*/
public Demo save(Demo demo) {
    return demoRepository.save(demo);
}

/**
* 删除
* @param id
*/
public void  delete(String id) {
    demoRepository.delete(id);
}
/**
* 根据id查询
* @param id
* @return
*/
public Demo findById(String id) {
    return demoRepository.findOne(id);
}


/**
* 分页查找
* @param demo
* @param pr
* @return
*/
public Page<Demo> getPageList(Demo demo, PageRequest pr) {
    Page<Demo> totalList = demoRepository.findAll(DemoSpecs.pageQueryDemo(demo), pr);
    return totalList;
}

}
